package com.test.reggieadmin.model.category;

import com.test.reggieadmin.base.BaseObserver;
import com.test.reggieadmin.base.BasePresenter;
import com.test.reggieadmin.bean.BaseBean;
import com.test.reggieadmin.bean.CategoryDetailsBean;

import java.util.Map;

public class AddCategoryPrensenter extends BasePresenter<AddCategoryView> {
    public AddCategoryPrensenter(AddCategoryView baseView) {
        super(baseView);
    }

    /**
     * 添加分类
     *
     * @param map
     */
    public void addCategory(Map<String, Object> map) {
        addDisposable(apiServer.addCategory(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.addCategorySuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据id查询员工信息
     *
     * @param id
     */
    public void categoryDetails(String id) {
        addDisposable(apiServer.categoryDetails(id), new BaseObserver<CategoryDetailsBean>() {
            @Override
            public void onSuccess(CategoryDetailsBean bean) {
                baseView.categoryDetailsSuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 修改分类
     *
     * @param map
     */
    public void updateCategory(Map<String, Object> map) {
        addDisposable(apiServer.updateCategory(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.updateCategorySuccess(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
